package com.gang.blog.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.gang.blog.dao.CommentMapper;
import com.gang.blog.domain.Comment;
import com.gang.blog.domain.Comment2;
import com.gang.blog.service.CommentService;

@Service("commentServiceImpl")
public class CommentServiceImpl implements CommentService {
	@Resource
	private CommentMapper commentMapper;
	
	
	public void setCommentMapper(CommentMapper commentMapper) {
		this.commentMapper = commentMapper;
	}

	/**
	 * 插入评论
	 */
	public boolean insertComment(Comment comment) {
		//设置mark表示插入执行的次数
		int mark = this.commentMapper.insert(comment);
		if(mark>0){
			return true;
		}else{
			return false;
		}
	}

	//按文章id查询comment列表
	public List<Comment> getCommentList(Integer articleId) {
		List<Comment> list = this.commentMapper.selectByArticleId(articleId);
		return list;
	}
	//对blog_comment和blog_user进行联表查询，将userName属性添加到blog_comment表中
	public List<Comment2> getCommentAndUser(Integer articleId) {
		List<Comment2> list = this.commentMapper.selectComAndUser(articleId);
		return list;
	}

}
